package com.txhy.certificatechain.presenter.pay;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.txhy.certificatechain.R;
import com.txhy.certificatechain.api.UrlAddress;
import com.txhy.certificatechain.presenter.base.BasePresenter;
import com.txhy.certificatechain.ui.view.pay.TransView;
import com.txhy.certificatechain.utils.GsonUtil;
import com.txhy.certificatechain.utils.LogUtil;
import com.txhy.certificatechain.utils.UIUtils;

/*
 * -----------------------------------------------------------------
 * Copyright (C) 2018-2030, by your company, All rights reserved.
 * -----------------------------------------------------------------
 * 文    件: TransPresenter.java
 * 作    者: 侯建军
 * 版    权: 1.0.0
 * 描    述: 转账
 * 创建时间: 2018/9/21 11:48
 * 更新时间：2018/9/21 11:48
 * -----------------------------------------------------------------
 * 2018/9/21 11:48: 创建 TransPresenter.java (侯建军);
 * -----------------------------------------------------------------
 */
public class TransPresenter extends BasePresenter<TransView> {


    public void backUser(String code, String reveUserId, String payUserId, String reveBelongType, String payBelongType) {
        getView().showProgress("正在加载...");
        LogUtil.e("1111",code+"-----------"+reveUserId+"------"+payUserId+"-----"+reveBelongType+"------"+payBelongType);
        OkGo.<String>post(UrlAddress.BACKUSER_URL)//
                .tag(this)//
                .params("code", code)
                .params("reveUserId", reveUserId)
                .params("payUserId", payUserId)
                .params("reveBelongType", reveBelongType)
                .params("payBelongType", payBelongType)
                .params("sign", "0")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        if (GsonUtil.GsonGetStatus(response.body()) == 200) {
                            getView().paySuccess(response.body());
                        } else {
                            getView().payFail(GsonUtil.GsonGetMsg(response.body()));
                        }
                        getView().hideProgress();
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        getView().payFail("请求失败请检查网络111");
                        getView().hideProgress();
                    }
                });
    }

    //login
    public void toFingerLogin(String phone, String meid, String type, String faceUrl) {
        getView().showProgress(UIUtils.getString(R.string.zaidianjia));
        OkGo.<String>post(UrlAddress.BIOLOGYCHECK_URL)//
                .tag(this)//
                .params("phone", phone)
                .params("meid", meid)
                .params("type", type)
                .params("faceUrl", faceUrl)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        if (GsonUtil.GsonGetStatus(response.body()) == 200) {
                            getView().fingerSuccess(GsonUtil.GsonGetData(response.body()));
                        } else {
                            getView().fingerFail(GsonUtil.GsonGetMsg(response.body()));
                        }
                        getView().hideProgress();
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        getView().fingerFail("请求失败请检查网络");
                        getView().hideProgress();
                    }
                });
    }


    //最终的付款
    public void endPay(String reveUserId, String money,  String jyb,String validCredit, String validPawn,
                       String bankMoney, String serviceMoney,String bankCard, String payUserId, String reveBelongType, String payBelongType,String reveReason,String payReason) {
        getView().showProgress(UIUtils.getString(R.string.zaidianjia));

        OkGo.<String>post(UrlAddress.CONFIRMIN_URL)//
                .tag(this)//
                .params("reveUserId", reveUserId)
                .params("money", money)
                .params("jyb", jyb)
                .params("validCredit", validCredit)
                .params("validPawn", validPawn)
                .params("bankMoney", bankMoney)
                .params("serviceMoney", serviceMoney)
                .params("bankCard", bankCard)
                .params("payUserId", payUserId)
                .params("reveBelongType", reveBelongType)
                .params("payBelongType", payBelongType)
                .params("sign", "1")
                .params("reveReason", reveReason)
                .params("payReason", payReason)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        if (GsonUtil.GsonGetStatus(response.body()) == 200) {
                            getView().endPaySuccess(GsonUtil.GsonGetMsg(response.body()));
                        } else {
                            getView().endPayFail(GsonUtil.GsonGetMsg(response.body())+"1111");
                        }
                        getView().hideProgress();
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        getView().endPayFail("请求失败请检查网络");
                        getView().hideProgress();
                    }
                });
    }
}
